<div id="middle">

    <div class="home_banner">
        <?php
        if (is_active_sidebar('home-ads-first-place')) :
            dynamic_sidebar('home-ads-first-place');
       
        endif;
        ?>
    </div>
    <div id="last_news">
        <?php
        
        include_once 'slideshow.php';
        ?>
    </div> <!-- #last_news -->
    <?php
    
    // Recent Posts
    query_posts('showposts=10');
    $i = 1;
    $new_articles = '';
    $new_posts_link = '';
    while (have_posts()) {
        the_post();
        

        if ($i <= 5) {
            
            $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
            $img = '<img src="'.TIMTHUMB_URL . $large_image_url[0] .'&amp;w='.THUMB_SMALL_WIDTH.'&amp;h='.THUMB_SMALL_HEIGHT.'&amp;zc=1&amp;q=100&amp;a=c" alt="' . get_the_title() . '" />';
            
            $new_articles .= '<div class="articles clearfix">';
            
            $new_articles .= '<div class="thumb"><a href="' . get_permalink() . '">' . $img . '</a></div>';
            $new_articles .= '<div class="title-summary"><h3><a href="' . get_permalink() . '">' . get_the_title() . '</a></h3>';
            $new_articles .= '<p>' . get_the_excerpt() . '...<a href="' . get_permalink() . '">អានលម្អិត</a></p></div>';

            $new_articles .= '</div>'; //end articl
            
        } else {
            $new_posts_link .= '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
            
        }
        $i++;
    } //end while
    wp_reset_query();
    
    // Popular Posts
    $mostpopular =  hc_popular_posts(7, 10);
    $num = 1;
    $popular_post = '';
    $link_popular_posts = '';
    foreach ($mostpopular as $p) {
        $post = get_post( intval( $p->id ) );
        setup_postdata( $post );
        
        if ($num <= 5) {
            
            $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
            $img = '<img src="'.TIMTHUMB_URL . $large_image_url[0] .'&amp;w='.THUMB_SMALL_WIDTH.'&amp;h='.THUMB_SMALL_HEIGHT.'&amp;zc=1&amp;q=100&amp;a=c" alt="' . get_the_title() . '" />';
            
            $popular_post .= '<div class="articles clearfix">';

            $popular_post .= '<div class="thumb"><a href="' . get_permalink() . '">' . $img . '</a></div>';
            $popular_post .= '<div class="title-summary"><h3><a href="' . get_permalink() . '">' . get_the_title() . '</a></h3>';
            $popular_post .= '<p>' . get_the_excerpt() . '...<a href="' . get_permalink() . '">អានលម្អិត</a></p></div>';

            $popular_post .= '</div>'; //end articl
        } else {
            $link_popular_posts .= '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
        }
        $num++;
    }
    ?>

    <div class="home_banner middle">
        <?php
        if (is_active_sidebar('home-ads-second-place')) :
            dynamic_sidebar('home-ads-second-place');
        endif;
        ?>
    </div>
    <div id="news_category">
        <div class="col_one" id="recent_posts">
            <div class="box_nc">
                <h2><a href="<?php echo WP_HOME ?>/recent-post/">អត្ថបទថ្មីៗ</a></h2>
                <div class="box_content">
                    <?php echo $new_articles; ?>
                    <ul class="title-link">
                        <?php echo $new_posts_link; ?>
                    </ul>
                </div><!-- box content -->
                <div class="more-posts"><h3><a href="<?php echo WP_HOME ?>/recent-post/"> >> អត្ថបទ​ផ្សេងទៀត</a></h3></div>
            </div>
        </div>
        <div class="col_two" id="popular_posts">
            <div class="box_nc">
                <h2><a href="<?php echo WP_HOME ?>/recent-post/">អត្ថបទនិយមអាន</a></h2>
                <div class="box_content">
                    <?php echo $popular_post ?>
                    <ul class="title-link">
                        <?php echo $link_popular_posts; ?>
                    </ul>
                </div> <!-- end box content -->
                <div class="more-posts"><h3><a href="<?php echo WP_HOME ?>/recent-post/"> >> អត្ថបទ​ផ្សេងទៀត</a></h3></div>
            </div>



        </div><!-- #col_two -->
        <div class="clearfix"></div>
        <div class="home_banner banner-bottom">
            <?php
            if (is_active_sidebar('home-ads-third-place')) :
                dynamic_sidebar('home-ads-third-place');
            endif;
            ?>
        </div>
    </div><!-- #news_category -->

</div><!-- #middle -->

